package com.sdp.wx.controller;


import com.sdp.core.bizc.vo.Result;
import com.sdp.wx.db.wx_ipc_menu.entity.WxIpcMenu;
import com.sdp.wx.db.wx_ipc_menu.service.IWxIpcMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zsp
 * @since 2024-02-29
 */
@RestController
@RequestMapping("/WxIpcMenuController")
public class WxIpcMenuController {
     @Autowired
    private IWxIpcMenuService iWxIpcMenuService;

    private String onlyofficeFiles = "onlyofficeFiles";

    @Value("${sdp.filePath}")
    private String filePath;


    @PostMapping(value = "/queryIpcMenuTreeSelect")
    public Result<?> queryIpcMenuTreeSelect() {
        return Result.ok(iWxIpcMenuService.queryIpcMenuTreeSelect());
    }

    @PostMapping(value = "/ipcMenuTableTree")
    public Result<?> ipcMenuTableTree() {
        return Result.ok(iWxIpcMenuService.queryIpcMenuTableTree());
    }

    @PostMapping(value = "/save")
    @Transactional(rollbackFor=Exception.class)
    public Result<?> save(@RequestBody WxIpcMenu wxIpcMenu) {
        if(wxIpcMenu == null) {
            return Result.error("提交信息为空");
        }
        if(StringUtils.isEmpty(wxIpcMenu.getKeyId())) {
            iWxIpcMenuService.save(wxIpcMenu);
        } else {
            iWxIpcMenuService.updateById(wxIpcMenu);
        }
        return Result.ok(wxIpcMenu);
    }

}

